const express = require('express');
const morgan = require('morgan');
const cors = require('cors');
// require('./models');
const app = express();
const logger = require('./logger');
// const productRoutes = require('./routes/productRoutes');
// const orderRoutes = require('./routes/orderRoutes');
const paymentRoutes = require('./routes/paymentRoutes');
app.use(morgan('dev'));
app.use(cors());
app.use(express.json())
app.use(express.urlencoded({extended:true}));
app.get('/',(req,res)=>{
  logger.info('wechatpay');
  res.send('wechatpay');
});
require('./swagger')(app);
// app.use('/api/products',productRoutes);
// app.use('/api/orders',orderRoutes);
app.use('/api/payment',paymentRoutes);
//如果有四个参数，第一个是错误
app.use((error,req,res,next)=>{
    logger.error('Error',error);
    res.status(500).send(`Internal Server Error`)
});
app.use((error,req,res,next)=>{
    res.status(400).send(`404: Page Not Found`)
});
module.exports = app;